package fun._6742.controller;

import fun._6742.request.GoodsStatusRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import fun._6742.model.valueobject.CartVO;
import fun._6742.request.CartItemRequest;
import fun._6742.service.CartService;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "购物车")
@RestController
@RequestMapping("api/cart/v1")
public class CartController {

    @Resource
    CartService cartService;

    @ApiOperation(value = "新增物品或更新数量",notes = "添加到购物车")
    @PostMapping("add")
    public void addGoodsToCart(@ApiParam(value = "购物车单项") @RequestBody CartItemRequest cartItemRequest){
        cartService.addItemToCartOrUpdate(cartItemRequest);
    }

    @ApiOperation(value = "清空",notes = "清空购物车")
    @DeleteMapping("clear")
    public void clearCart(){
        cartService.delAllCartItems();
    }

    @ApiOperation(value = "列表",notes = "查看购物车")
    @GetMapping("cart")
    public CartVO viewCart(){
        return cartService.viewCart();
    }

    @ApiOperation(value = "移除",notes = "移除购物车子项")
    @DeleteMapping("remove")
    public void removeCartItem(@ApiParam(value = "购物车单项") @RequestBody List<Long> productIds){
        cartService.delBatchCartItems(productIds);
    }

    @ApiOperation(value = "状态变更",notes = "购物车子项状态变更")
    @PostMapping("status")
    public void changeCartItemStatus(@ApiParam(value = "购物车单项状态") @RequestBody GoodsStatusRequest goodsStatusRequest){
        cartService.updateCartItems(goodsStatusRequest);
    }











}
